import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class Array_Visualisation extends JFrame

{
	//JButton button[][] = new JButton[Mapping_Main.no_cfu_row_int][Mapping_Main.no_cfu_column_int];
	JButton button[][] = new JButton[8][8];
	String cfu_name = "";
	int cfu_column_index = 0;
	int cfu_row_index=0;
	
	public Array_Visualisation() {
		JPanel p1 = new JPanel();
		//p1.setLayout(new GridLayout(Mapping_Main.no_cfu_row_int, Mapping_Main.no_cfu_column_int, 5, 5));
		
		p1.setLayout(new GridLayout(8, 8, 5, 5));
		

		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) {
				button[i][j] = new JButton("CFU" + Integer.toString(i + 1)
						+ Integer.toString(j + 1));
				p1.add(button[i][j]);
				button[i][j].addActionListener(new ActionListener() {
			
					
					public void actionPerformed(ActionEvent ae)
					{
						cfu_name = ae.getActionCommand().substring(3);
//						JOptionPane.showMessageDialog(null, cfu_name);
						
						// Getting row number of the object which is responsible for the event
						cfu_row_index = Character.getNumericValue(cfu_name.charAt(0));
						JOptionPane.showMessageDialog(null,cfu_row_index);
						
//						 Getting column number of the object which is responsible for the event
						cfu_column_index = Character.getNumericValue(cfu_name.charAt(1));
						JOptionPane.showMessageDialog(null,cfu_column_index);
						 JOptionPane.showMessageDialog(null, Mapping_Main.Cfu_Array[cfu_row_index-1][cfu_column_index-1].register_array[0]);
					//JOptionPane.showMessageDialog(null,"You have pressed "+ ae.getActionCommand().substring(3));
					}
					
				});
			}
		}
		Container c = getContentPane();
		c.add(p1);

		int l;
		int m;
		
//		for (l = 0; l < 8; l++) {
//
//			for (m = 0; m < 8; m++) {
//				button[l][m].addActionListener(new ActionListener() {
//					public void actionPerformed(ActionEvent evt) {
////						System.out.println("jButton1.actionPerformed, event="+ evt);
//						// TODO add your code for jButton1.actionPerformed
//						JOptionPane.showMessageDialog(null, "Jai Sairam");
//						JOptionPane
//								.showMessageDialog(
//										null,
//										"Register 1  "
//												+ Mapping_Main.Cfu_Array[l][m].register_array[1]);
//					}
//				});
//			}
//		}
		

		

		

		setTitle("Testing button");
		setSize(800, 800);
		setVisible(true);

	}
	
	
	public void actionPerformed(ActionEvent evt)
	{
		JOptionPane.showMessageDialog(null,"You have pressed "+ evt.getSource());
//		JOptionPane
//		.showMessageDialog(
//				null,
//				"Register 1  "
//						+ Mapping_Main.Cfu_Array[1][1].register_array[1]);
	}

	public static void main(String[] args) {
		new Array_Visualisation();

	}
}